<#-- Includes -->
<#include "propertyutils.ftl">

<#-- Renders filter params for link -->
<#macro renderLinkFilterParams componentName>
<#foreach prop in pojo.allPropertiesIterator>
<#if !c2h.isCollection(prop) && !isToOne(prop) && prop != pojo.versionProperty!>
<#if pojo.isComponent(prop)>
<#foreach nestedProp in prop.value.propertyIterator>
<#if isString(nestedProp)>
  <stripes:param name="${componentName}.${prop.name}.${nestedProp.name}" value="${'$'}{actionBean.${componentName}.${prop.name}.${nestedProp.name}}"/>
<#elseif isDate(nestedProp) || isTimestamp(nestedProp) || isTime(nestedProp)>
  <stripes:param name="${nestedProp.name}From" value="${'$'}{actionBean.${nestedProp.name}From}"/>
  <stripes:param name="${nestedProp.name}To" value="${'$'}{actionBean.${nestedProp.name}To}"/>
</#if>
</#foreach>
<#else>
<#if isString(prop)>
  <stripes:param name="${componentName}.${prop.name}" value="${'$'}{actionBean.${componentName}.${prop.name}}"/>
<#elseif isDate(prop) || isTimestamp(prop) || isTime(prop)>
  <stripes:param name="${prop.name}From" value="${'$'}{actionBean.${prop.name}From}"/>
  <stripes:param name="${prop.name}To" value="${'$'}{actionBean.${prop.name}To}"/>
</#if>
</#if>
</#if>
</#foreach>
</#macro>

<#-- Renders string cell of result list row -->
<#macro renderStringCell rowIteratorName propName nestedPropName="">
  <td>${'$'}{${rowIteratorName}.${propName}<#if nestedPropName != "">.${nestedPropName}</#if>}</td>
</#macro>

<#-- Renders date/time cell of result list row -->
<#macro renderDateTimeCell rowIteratorName propName nestedPropName="">
  <td><fmt:formatDate value="${'$'}{${rowIteratorName}.${propName}<#if nestedPropName != "">.${nestedPropName}</#if>}" dateStyle="medium"/></td>
</#macro>

<#-- Renders one cell of result list row -->
<#macro renderResultCell rowIteratorName prop nestedProp=0 hasNested=false>
<#assign tmp = prop/>
<#assign nestedPropName = ""/>
<#if hasNested>
<#assign tmp = nestedProp/>
<#assign nestedPropName = nestedProp.name />
</#if>
<#if isDate(tmp) || isTimestamp(tmp) || isTime(tmp)>
  <@renderDateTimeCell rowIteratorName=rowIteratorName propName=prop.name nestedPropName=nestedPropName/>
<#else>
  <@renderStringCell rowIteratorName=rowIteratorName propName=prop.name nestedPropName=nestedPropName/>
</#if>
</#macro>

<#-- Renders all cells of result list row -->
<#macro renderResultCells rowIteratorName picker=false>
<#assign propertyList = createPropertyList()/>
<#foreach prop in propertyList>
<#if pojo.isComponent(prop)>
<#foreach nestedProp in prop.value.propertyIterator>
<#if !picker || (!(nestedProp.name?matches("id.*")) && !(nestedProp.name?matches("[pP]icker[dD]isplay"))) >
  <@renderResultCell rowIteratorName=rowIteratorName prop=prop nestedProp=nestedProp hasNested=true/>
</#if>
</#foreach>
<#else>
  <@renderResultCell rowIteratorName=rowIteratorName prop=prop/>
</#if>
</#foreach>
</#macro>

<#--
@brief Renders header cell for result list
@param controllerPackage name of controller package
@param entityName name of current entity
@param prop property that should be rendered
@param nestedProp nested property of prop
@param hasNested indicator whether is property nested or not
@param picker true/false if this macro is/isn't used for generation of entity picker
-->
<#macro renderResultHeaderCell controllerPackage entityName prop nestedProp=0 hasNested=false picker=false>
<#assign listType="List"/>
<#if picker>
<#assign  listType="PickerList"/>
</#if>
  <th>
    <stripes:link beanclass="${controllerPackage}.${entityName}${listType}" event="doFilter">
      <@renderLinkFilterParams componentName=componentName />
      <stripes:param name="orderBy" value="${prop.name}<#if hasNested>.${nestedProp.name}</#if>"/>
      <c:if test="${'$'}{actionBean.orderBy == \"${prop.name}<#if hasNested>.${nestedProp.name}</#if>\"}">
        <stripes:param name="orderAsc" value="${'$'}{! actionBean.orderAsc}"/>
      </c:if>
      <stripes:label for="${componentName}.${prop.name}<#if hasNested>.${nestedProp.name}</#if>"/>
    </stripes:link>
    <c:if test="${'$'}{actionBean.orderBy == \"${prop.name}<#if hasNested>.${nestedProp.name}</#if>\"}">
      <c:choose>
        <c:when test="${'$'}{actionBean.orderAsc}">
          <fmt:message bundle="${'$'}{msgs}" key="up"/>
        </c:when>
        <c:otherwise>
          <fmt:message bundle="${'$'}{msgs}" key="down"/>
        </c:otherwise>
      </c:choose>
    </c:if>
  </th>
</#macro>

<#--
@brief Renders header cells for result list
@param controllerPackage name of controller package
@param entityName name of current entity
@param picker true/false if this macro is/isn't used for generation of entity picker
@param omitCols comma separated names of columns that should be omitted
-->
<#macro renderResultHeaderCells controllerPackage entityName picker=false omitCols="">
<#assign componentName = entityName?uncap_first/>
<#assign propertyList = createPropertyList()/>
<#foreach prop in propertyList>
<#if pojo.isComponent(prop)>
<#foreach nestedProp in prop.value.propertyIterator>
<#if !picker || (!(nestedProp.name?matches("id.*")) && !(nestedProp.name?matches("[pP]icker[dD]isplay"))) >
  <@renderResultHeaderCell controllerPackage=controllerPackage entityName=entityName prop=prop nestedProp=nestedProp hasNested=true picker=picker/>
</#if>
</#foreach>
<#else>
  <@renderResultHeaderCell controllerPackage=controllerPackage entityName=entityName prop=prop picker=picker />
</#if>
</#foreach>
</#macro>
